<template>
    <div id="register">
        <el-form ref="form" :model="form" label-width="80px">
            <el-form-item label="学号/工号">
                <el-input v-model="form.userName"></el-input>
            </el-form-item>
            <el-form-item label="密码">
                <el-input v-model="form.password" type="password"></el-input>
            </el-form-item>
            <el-form-item label="确认密码">
                <el-input v-model="form.rePassword" type="password"></el-input>
            </el-form-item>
            <!-- <el-form-item label="真实姓名">
                <el-input v-model="form.nickName"></el-input>
            </el-form-item>
            <el-form-item label="邮箱">
                <el-input v-model="form.email"></el-input>
            </el-form-item> -->
            <el-form-item label="手机号">
                <el-input v-model="form.phoneNumber"></el-input>
            </el-form-item>
            <el-form-item>
                <el-button type="primary" @click="onSubmit">立即注册</el-button>
                <a style="margin-left:20px; cursor: pointer; color: #409eff;" @click="loginBtn">去登录</a>
            </el-form-item>
        </el-form>
    </div>
</template>

<script>

import { register } from '@/api/user'
export default {
    data() {
        return {
            form: {
                userName: '',
                region: '',
                date1: '',
                password: '',
                rePassword: '',
                phoneNumber: '',
                delivery: false,
                type: [],
                resource: '',
                desc: ''
            }
        }
    },
    methods: {
        loginBtn() {
            this.$router.push({ path: '/login' })
        },
        onSubmit() {
            console.log('submit!');
            let objSend = {
                userName: this.form.userName,
                password: this.form.password,
                phoneNumber: this.form.phoneNumber
            }
            register(objSend).then(res => {
                this.$message({
                    type: 'warning',
                    message: res.data
                });
                if(res.data == '注册成功'){
                    this.$router.push({
                        path: "/login",
                    });
                }
            }).catch(error => {
                reject(error)
            })

        }
    }
}
</script>


<style>
#register {
    width: 40%;
    margin: 20px;
}
</style>